package com.xiguanlezz.cn.consumer.proxy;

import com.xiguanlezz.cn.consumer.proxy.config.ProxyConfig;

import java.util.Objects;

/**
 * @Author：习惯了种种
 * @CreateDate：2024/11/12 21:25
 * @Description：代理工厂基类
 */
public abstract class BaseProxyFactory<T> implements ProxyFactory {
    protected ObjectProxy<T> objectProxy;

    @SuppressWarnings("unchecked")
    @Override
    public <T> void init(ProxyConfig<T> proxyConfig) {
        if (Objects.isNull(proxyConfig)) {
            throw new RuntimeException("proxyConfig must no null...");
        }
        this.objectProxy = new ObjectProxy(
                proxyConfig.getInterfaceClazz(),
                proxyConfig.getServiceVersion(),
                proxyConfig.getServiceGroup(),
                proxyConfig.getInvokeTimeout(),
                proxyConfig.getSerializerType(),
                proxyConfig.getInvokeMethodType(),
                proxyConfig.getConsumer()
        );
    }
}
